package com.infinitegroup.findmystuff.presenters;

import java.util.List;
import java.util.Map;

import android.content.Context;

import com.infinitegroup.findmystuff.models.Account;
import com.infinitegroup.findmystuff.models.AccountLink;
import com.infinitegroup.findmystuff.models.Item;
import com.infinitegroup.findmystuff.models.ItemLink;
import com.infinitegroup.findmystuff.views.ViewAllView;


public class ViewAllPresenter{
	
	private Item item;
	private ViewAllView view;
	
	private String category, status; // the category and status variables on which 
	private boolean date = false;
	
	public ViewAllPresenter(ViewAllView view){
		this.view = view;
		this.item = new ItemLink((Context) view);
	}
	
	/**
	 * Gets items associated with the username and returns them as a list of maps.
	 * @return List of items (maps).
	 */
	public List<Map<String,String>> getItemsToDisplay(String category, String status, String orderBy) {
		try{
			List<Map<String,String>> items = item.getItemsFilteredBy(null, null, status, category, orderBy);
			if (items.isEmpty()){
				view.displayMessage("No items found.");
				return null;
			} else {
				return items;
			}
		} catch (Exception e){
			view.displayMessage("Could not fetch items from database");
			return null;
		}
	}
	
	
	public void handleFilterClick(String category, String status, String orderBy){
		try{
			List<Map<String,String>> items = item.getItemsFilteredBy(null, null, status, category, orderBy);
			if (items.isEmpty()){
				view.displayMessage("No items found.");
			} else {
				view.generateViewAllScreen(items);
			}
		} catch (Exception e){
			view.displayMessage("Could not fetch items from database");
		}
		
	}
	
	public void handleReturnToHomeClick(){
		view.end();
	}

}
